function int = acrubond(id, sd, fd, rv, cpn, per, basis)
%ACRUBOND Accrued interest of security with periodic interest payments.
%   ACRUBOND returns the accrued interest for a security with standard, short,
%   and long first coupon periods.
%
%   INT = acrubond(ID, SD, FD, RV, CPN)
%   INT = acrubond(ID, SD, FD, RV, CPN, PER, BASIS)
%
%   Optional Inputs: PER, BASIS
%
%   Inputs:
%      ID - Scalar or vector of the issue dates as serial date numbers or date
%           strings.
%
%      SD - Scalar or vector of the settlement dates as serial date numbers or
%           date strings.
%
%      FD - Scalar or vector of the first coupon dates as serial date numbers
%           or date strings.
%
%      RV - Scalar or vector of the par values.
%
%     CPN - Scalar or vector of the coupon rates.
%
%   Optional Inputs:
%     PER - Scalar or vector of the number of coupon periods per year
%           (default = 2).
%
%   BASIS - Scalar or vector of the day-count basis.
%           Valid basis include:
%              0 - actual/actual (default)
%              1 - 30/360     SIA
%              2 - actual/360
%              3 - actual/365
%              4 - 30/360     PSA
%              5 - 30/360     ISDA
%              6 - 30E/360
%              7 - actual/365 Japanese.
%              8 - actual/actual ISMA
%              9 - actual/360 ISMA
%             10 - actual/365 ISMA
%             11 - 30/360 ISMA
%             12 - actual/365 ISDA
%             13 - bus/252
%
%   Outputs:
%   INT - Scalar or vector of accrued interest.
%
%   Example:
%
%   int = acrubond('31-jan-1983', '1-mar-1993', '31-jul-1983', 100, 0.1, 2, 0)
%
%   int = 0.8011.
%
%   See also ACRUDISC, CFAMOUNTS, ACCRFRAC
%
%   Note: cfamounts or accrfrac is recommended when calculating accrued
%         interest beyond the first period.

%       Copyright 1995-2006 The MathWorks, Inc.
%       $Revision: 1.9.2.9 $   $Date: 2009/05/07 18:23:14 $

% Checking the input arguments
if nargin < 7
    basis = 0;
end

if nargin < 6
    per = 2;
end

if nargin < 5
    error('Finance:acrubond:missingInputs', 'Too few inputs.')
end

% Calculate the accrued interest
CFlowAmounts = cfamounts(cpn, sd, datemnth(max(datenum(fd), ...
    datenum(sd)), 12), per, basis,[], id, fd, [], [], rv);

int = abs(CFlowAmounts(:, 1));